package org.embedded.browser;

import java.io.File;

import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.LocationEvent;
import org.eclipse.swt.browser.LocationListener;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Test {
  public void init(){
    Display display = new Display();
    Shell shell = new Shell(display,SWT.MIN);
    final Chromium chromium = new Chromium(shell, SWT.NO_TRIM);
    chromium.setUrl("www.baidu.com");
//    chromium.setUrl("http://www.5iweb.com.cn/resource/5iweb2015110602/index.html");
    chromium.setBounds(0, 0, 900, 600);
    chromium.addCloseWindowListener(new CloseWindowListener() {
      public void HandleCloseWindow(Chromium c) { ((CTabItem)c.getData()).dispose(); }
  });
    chromium.addNewWindowListener(new NewWindowListener() {
      
      @Override
      public void HandleNewWindow(Chromium arg0, String arg1) {
         System.out.println(arg1);
          arg0.setUrl(arg1);
          
      }
  });

    
    shell.setVisible(true);
    shell.setBounds(100, 100, 900, 600);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    shell.dispose();
    display.dispose();
  }
  
  
  public static void main(String[] args) {
    Test t = new Test();
    t.init();
    
  }
}
